//商品详情展示
function showDetail(goodsId) {
    $.ajax({
        url : "goods/query/normal",
        async : true,
        type : "GET",
        data : {
            "goodsId" : goodsId
        },
        // 成功后开启模态框
        success : queryDetail,
        error : function(res) {
            alert("商品信息获取失败");
        },
        dataType : "json"
    });
}
function queryDetail(res) {
    if(res.code!=0){
        alert(res.msg);
    }
    var model = res.data;
    $("#d_goodsName").text(model.goodsName);
    $("#d_goodsParam").text(model.goodsParam);
    $("#d_goodsPic").attr('src',model.goodsPic);
    $("#d_goodsPrice").text(model.goodsPrice);
    var typeName;
    switch (model.goodsType) {
        case 1: typeName="食品/保健类"; break;
        case 2: typeName="服饰类"; break;
        case 3: typeName="皮具箱包类"; break;
        case 4: typeName="珠宝饰品类"; break;
        case 5: typeName="母婴/儿童类"; break;
        case 6: typeName="家电类"; break;
        case 7: typeName="数码类"; break;
        case 8: typeName="汽车配件类"; break;
        case 9: typeName="家具/建材类"; break;
        case 10: typeName="图书影音类"; break;
        default: typeName="不限";
    }
    $("#d_goodsType").text(typeName);
    $("#d_goodsStock").text(model.goodsStock);
    $("#d_goodsSales").text(model.goodsSales);
    $("#d_shopName").text(model.shopName);
    $("#d_goodsAddr").text(model.goodsAddr);
    $("#d_goodsTime").text(model.goodsTime);
    $("#d_modifyTime").text(model.modifyTime);

    // 显示模态框
    $('#detailModal').modal('show');
}


//商品上架
function showUpper(goodsId) {
    if (confirm("是否确认重新上架该商品？")) {
        $.ajax({
            type: 'get',
            url: 'goods/upper/normal',
            dataType: 'json',
            data: {
                "goodsId": goodsId,
                "isUpper": 1
            },
            contentType: false, //不设置内容类型
            error: function (request) {
                alert("未知错误，上架失败");
            },
            success: function (res) {
                if (res.code == 0) {
                    alert("上架商品成功！");
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            }
        });
    }
}

//商品删除
function showDelete(goodsId) {
    if (confirm("请慎重删除商品，建议选择下架或编辑。\n\r是否确认删除该商品？")) {
        $.ajax({
            type: 'get',
            url: 'goods/delete/normal',
            dataType: 'json',
            data: {
                "goodsId": goodsId
            },
            contentType: false, //不设置内容类型
            error: function (request) {
                alert("未知错误，删除失败");
            },
            success: function (res) {
                if (res.code == 0) {
                    alert("删除商品成功！");
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            }
        });
    }
}